package com.doit.demo01;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test_Year {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入您的生日日期(yyyy-MM-dd):");
        String sheng = sc.nextLine();
        System.out.println("您活了"+day(sheng)+"天");
    }

    private static int day(String sheng) throws ParseException {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date b = df.parse(sheng);//字符串转成日期
        long time = b.getTime();//获得毫秒值
        long time1 = new Date().getTime();//获得初始毫秒值
        int day = (int) ((time1-time)/1000/60/60/24);

        return day;
    }
}
